import static org.junit.Assert.*;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import org.junit.Test;


public class breedingTest
{
	private static final double RABBIT_CREATION_PROBABILITY = 0.08; 
	SimulatorView tester = new SimulatorView(100, 100);
	ArrayList<Animal> animals = new ArrayList<Animal>();
    Field field = new Field(100, 100);
    Random rand = Randomizer.getRandom();

	@Test
	public void test()
	{
	    tester.setColor(Rabbit.class, Color.ORANGE);
	    field.clear();
        for(int row = 0; row < field.getDepth(); row++) 
        {
            for(int col = 0; col < field.getWidth(); col++) 
            {
            	if(rand.nextDouble() <= RABBIT_CREATION_PROBABILITY) 
            	{
                    Location location = new Location(row, col);
                    Rabbit rabbit = new Rabbit(true, field, location);
                    animals.add(rabbit);
                }
            }
        }
        field.clear();
     // Provide space for newborn animals.
        List<Animal> newAnimals = new ArrayList<Animal>();        
        // Let all rabbits act.
        for(Iterator<Animal> it = animals.iterator(); it.hasNext(); ) {
            Animal animal = it.next();
            Rabbit rabbit = (Rabbit)animal;
            Location location = rabbit.getLocation();
            assertTrue("Breeding is wrong..", field.getFreeAdjacentLocations(location) != null);
            animal.act(newAnimals);
            if(! animal.isAlive()) {
                it.remove();
            }
        }
               
        // Add the newly born foxes and rabbits to the main lists.
        animals.addAll(newAnimals);
        tester.showStatus(1, field);
	}
}
